Development#21
Conversation
There was a problem hiding this comment.
Pull request overview
This PR extends the Lumen /radio API to support getting/setting the radio’s digital voice mode, and updates user lookup to use primary-key ID rather than email.
Changes:
- Added
GET /radio/voice/digitalandPOST /radio/voice/digital/{value}routes. - Implemented
RadioController@getDigitalVoiceandRadioController@setDigitalVoice. - Updated
UserController@showOneUserto useUser::find($id).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| routes/web.php | Registers two new digital voice endpoints under the /radio route group. |
| app/Http/Controllers/UserController.php | Switches single-user lookup to primary-key ID via User::find($id). |
| app/Http/Controllers/RadioController.php | Adds digital voice get/set actions and adjusts power-level validation area. |
Comments suppressed due to low confidence (1)
app/Http/Controllers/RadioController.php:988
- If
powerLevelis outside 0..100, the firstifblock is skipped and$outputis never set, but it is still read inif ($output == "OK"), which will raise an undefined variable notice and return a 500. Add an explicitelse/early return for invalidpowerLevel(and avoid referencing$outputwhen the command was not executed).
if ($request->powerLevel >= 0 && $request->powerLevel <= 100) {
$command = "set_power -a " . $request->powerLevel . " -p " . $request->profile;
$output = explode("\n", (string) exec_uc($command))[0];
}
if ($output == "OK") {
return response(true, 200);
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function setDigitalVoice(Request $request) | ||
| { | ||
| if ($request->value < 0 || $request->value > 1) { | ||
| (new ErrorController)->saveError(static::class, 500, 'API Error: digital voice value must be 0 or 1'); | ||
| return response()->json(['message' => 'Server error'], 500); | ||
| } | ||
|
|
||
| $command = "set_digital_voice -a " . $request->value. " -p 1"; |
| { | ||
| if ($request->value < 0 || $request->value > 1) { | ||
| (new ErrorController)->saveError(static::class, 500, 'API Error: digital voice value must be 0 or 1'); | ||
| return response()->json(['message' => 'Server error'], 500); | ||
| } | ||
|
|
||
| $command = "set_digital_voice -a " . $request->value. " -p 1"; |
| $output = explode("\n", (string) exec_uc($command))[0]; | ||
|
|
||
| if ($output == "OFF" || $output == "ON") { | ||
| return response()->json($output, 200); |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
app/Http/Controllers/RadioController.php:991
- If
powerLevelis outside the allowed range,$outputis never set, but the code still evaluatesif ($output == "OK")and logs with... - $output, which can trigger an undefined variable notice and obscure the real problem. Return a 4xx response (and avoid executing the command) when validation fails, and ensure$outputis always defined before it is used.
if ($request->powerLevel >= 0 && $request->powerLevel <= 100) {
$command = "set_power -a " . $request->powerLevel . " -p " . $request->profile;
$output = explode("\n", (string) exec_uc($command))[0];
}
if ($output == "OK") {
return response(true, 200);
}
(new ErrorController)->saveError(static::class, 500, 'API Error: Error during updating the power level - ' . $output);
return response()->json(['message' => 'Server error'], 500);
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
app/Http/Controllers/RadioController.php:991
- If
powerLevelis outside 0..100, the$outputvariable is never set, but it is still referenced in the subsequentif ($output == "OK")and error logging. This will trigger an undefined variable notice and can mask the real validation failure. Return a clear validation response when out of range (or set a default/else branch) before using$output.
if ($request->powerLevel >= 0 && $request->powerLevel <= 100) {
$command = "set_power -a " . $request->powerLevel . " -p " . $request->profile;
$output = explode("\n", (string) exec_uc($command))[0];
}
if ($output == "OK") {
return response(true, 200);
}
(new ErrorController)->saveError(static::class, 500, 'API Error: Error during updating the power level - ' . $output);
return response()->json(['message' => 'Server error'], 500);
This pull request introduces new API endpoints for managing the digital voice mode of the radio, improves error handling and validation in user and radio controller methods, and makes minor code cleanups. The most important changes are summarized below:
Digital Voice Mode API Enhancements:
getDigitalVoiceandsetDigitalVoice, toRadioControllerfor retrieving and updating the digital voice mode. These methods include input validation, command execution, and error logging.routes/web.phpfor the new digital voice endpoints:GET radio/voice/digitalandPOST radio/voice/digital/{value}.User Controller Improvements:
UserController@showOneUserto useUser::find($id)instead of searching by email, ensuring the lookup is by user ID and improving reliability.Radio Controller Validation and Cleanup:
RadioController@setPowerLevelby ensuring thepowerLevelis within the valid range before executing the command.